<?php
ini_set("display_errors", "On");

define('S_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);
include_once S_ROOT."class/db/ez_sql_core.php";
include_once S_ROOT."class/db/ez_sql_mysql.php";

$db = new ezSQL_mysql('root','Ngjj1917','xunlianri','localhost','utf-8');

$sql = "select * from api order by api_type";
$api_list = $db->get_results($sql);

$sql = "select * from api_param order by api_id ";
$param_list = $db->get_results($sql);


foreach ($api_list as $api) {
    $api_id = $api->id;
    $api->params = array();

    foreach ($param_list as $param) {
        $param_api_id = $param->api_id;

        if($param_api_id == $api_id){
            $api->params[] = $param;
        }
    }
}
  

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>XAPI</title>
            <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
            <script type="text/javascript" src='/include/layer.m.js'>
            </script>

             <script type="text/javascript" src="/js/jquery.1.10.1.min.js">
            </script>

            <script type="text/javascript" src="/bootstrap/js/bootstrap.js">
            </script>
</head>

<style>
    body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:0;padding:0;word-wrap:break-word; font-weight: normal; }
    body,html,input{font:14px/1.5 tahoma,arial,\5b8b\4f53,sans-serif;}
    table{border-collapse:collapse;border-spacing:0;}img{border:none}
    pre {white-space: pre-wrap; /* css-3 */white-space: -moz-pre-wrap; /* Mozilla, since 1999 */white-space: -pre-wrap; /* Opera 4-6 */white-space: -o-pre-wrap; /* Opera 7 */  word-wrap: break-word; /* Internet Explorer 5.5+ */}
    h1,h2,h3,h4,h5,h6{font-size:100%;}input.dialog{height:0; height:0; font-size:0; line-height:0; border:none}
    h1{font-size:34px;}h2{font-size:26px;}h3{font-size:18px; }h4{font-size:16px;}h5{font-size:14px;}h6{font-size:12px;}
    input,label,img,th{vertical-align:middle;}.font-fixh{font-family: Georgia,Arial; color: #f00; font-size: 16px; font-weight: 700;}address,cite,dfn,em,var{font-style:normal;}
    code,kbd,pre,samp{font-family:courier new,courier,monospace;}
    input.button ,input.btn{padding:0.25em;width: auto;_width:0;overflow:visible !ie;}
    ul,ol,li{list-style:none;padding: 0px; margin: 0px}
    a{text-decoration:none; color: #333333}
    a:hover{text-decoration:none; color: #ee602e }
    *{box-sizing:border-box;}
    .ad{height: 100px;  }

    html, body { position: relative; }

    .clearfix:after { content:"."; display:block; height:0; visibility:hidden; clear:both; }  
    .clearfix { zoom:1; }    

    ul:after { content:"."; display:block; height:0; visibility:hidden; clear:both; }  
    ul{ zoom:1; }    
    .apitable{width:100%;margin:20px;}
    .apitable td{padding:5px;}
    .apiwrap{margin-top:30px;}
    .apiwrap h3{margin-left:20px;color:#1588CB; position:relative}
    .apiwrap h3 span{position:absolute;right:20px;}
    .apiwrap h3 span a{font-size:14px; color:#999999}

    .apitable tr{border-bottom:1px solid #dddddd}
    .apitable .headtr{background-color:#EBF7FF; border-bottom:0px;font-weight:bold}

    .headtable {margin:10px; border:1px solid #dddddd; width:500px;}
    .headtable td{padding:5px; border-bottom:1px solid #dddddd}

    #apititle{padding:10px;}
    #apititle a{color:#1588CB}
    #apititle li{line-height:25px;}

</style>
        
<body>

<div style="width:1000px; margin:auto;">

   <div style="line-height:100px; font-size:24px; text-align:center">训练日API </div>

   <div style="margin-top:40px">
       <h3>接口目录</h3>
        
       <ul id="apititle">
       <?php
            $no = 0;
            $sub = 0;
            foreach($api_list as $api){
                $currentsub =  $api->api_type;
                
                if($currentsub!=$sub){
                    $no = 1;
                }else{
                    $no ++;
                }
       ?>
          <li>
             <a href="#<?php echo($api->id); ?>">  
                  <?php echo($api->api_type); ?>.<?php echo($no); ?> <?php echo($api->api_name); ?>
             </a>
          </li>            
       <?php
             $sub =  $api->api_type ;
          }
       ?>

       </ul>

   </div>

   <div style="margin-top:40px">
       <h3>一、概述</h3>

       <div style="margin-top:20px;font-size:16px; ">
           <h3>  1.1 API采用HTTP JSON基础的接口规范。所有的API都是通过HTTP POST或GET向服务器发送请求来实现的。</h3>
       </div>

       <div  style="margin-top:20px;">
         <h3> 1.2 接口地址</h3>
          http://120.24.177.211/api/api.php
       </div>

       <div  style="margin-top:20px;">
         <h3>1.3 请求包头(放置在Http包头)</h3>
         <table class="headtable">
            <tr><td>字段</td><td>说明</td></tr>
            <tr><td>appid</td><td>客户端类型ID</td></tr>
            <tr><td>sign</td><td>md5(app_key+requestid) </td></tr>
            <tr><td>requestid</td><td>时间戳</td></tr>
         </table>
       </div>

       <div  style="margin-top:20px;">
         <h3>1.4 app_key </h3>
         <table class="headtable">
            <tr><td>appid</td>  <td>app key</td> <td>说明</td></tr>
            <tr><td>1</td> <td> 8a3b7ce5a1b506d5 </td> <td>iphone app id</td>  </tr>
            <tr><td>2</td> <td> a1d3c3cf320df1d9 </td> <td>android app id</td> </tr>
          </table>
       </div>


   </div>


   <div style="margin-top:40px">
       <h3>二、约练接口</h3>
       
   <?php
        $no = 0;
        $sub = 0;
        foreach($api_list as $api){
            $currentsub =  $api->api_type;
            
            if($currentsub!=$sub){
                $no = 1;
                if($currentsub=='3'){
                    echo("</div> <div style='margin-top:40px'><h3>三、发现接口</h3>");
                }
                if($currentsub=='4'){
                    echo("</div> <div style='margin-top:40px'><h3>四、消息接口</h3>");
                }
                if($currentsub=='5'){
                    echo("</div> <div style='margin-top:40px'><h3>五、我的接口</h3>");
                }


            }else{
                $no ++;
            }

            
            $params = $api->params;
    ?>
       <div class="apiwrap" id="<?php echo($api->id); ?>">
          <h3> <?php echo($api->api_type); ?>.<?php echo($no); ?> <?php echo($api->api_name); ?> <span><a href="#top">top</a></span> </h3> 

              <table class="apitable">
                 <tr class="headtr"><td colspan="4">输入参数</td></tr>
                 <tr>
                     <td style="width:25%">参数名</td> <td style="width:25%">是否必填</td> <td style="width:50%">描述</td>
                 </tr>
                 <tr>
                     <td style="width:25%">action</td> <td style="width:25%">1</td> <td style="width:50%"><?php echo($api->api_url); ?></td>
                 </tr>

               <?php
                    foreach($params as $param){
                        if($param->param_type!=1){
                            continue;
                        }
                ?>
                     <tr>
                        <td><?php echo($param->param_name); ?></td><td><?php echo($param->ifmust); ?></td><td><?php echo($param->param_desc); ?></td>
                     </tr>
                <?php
                     }
                ?>
               
     
                 <tr class="headtr" ><td colspan="4">输出参数</td></tr>
               <?php
                    foreach($params as $param){
                        if($param->param_type!=2){
                            continue;
                        }
                ?>
                     <tr>
                        <td><?php echo($param->param_name); ?></td><td><?php echo($param->ifmust); ?></td><td><?php echo($param->param_desc); ?></td>
                     </tr>
                <?php
                     }
                ?>
               

             </table>



       </div>
   <?php
                 $sub =  $api->api_type ;
     }
   ?>

 

   </div>


   <div style="margin-top:40px">
       <h3>六、错误码</h3>
       
       <ul>
          <li>

          </li>


       </ul>

   </div>





</div>

</body>


 </html>
